﻿using System;

using System.IO;

using System.Threading.Tasks;



public class FileCopyManager

{

    private string sourceDir;

    private string targetDir;



    public FileCopyManager(string source, string target)

    {

        sourceDir = source;

        targetDir = target;

        Directory.CreateDirectory(targetDir);

    }



    public void CopyFilesWithMultiThread()

    {

    

        foreach (string file in files)

        {

            Task.Run(() =>

            {

                string fileName = Path.GetFileName(file);

                string targetPath = Path.Combine(targetDir, fileName);

                File.Copy(file, targetPath, true);

                Console.WriteLine($"线程 {Task.CurrentId} 拷贝完成：{fileName}");

            });

        }

    }

}



class Program

{

    static void Main(string[] args)

    {

        string source = @"D:\SourceDir";

        string target = @"D:\TargetDir";



        FileCopyManager manager = new FileCopyManager(source, target);

        manager.CopyFilesWithMultiThread();



        Console.WriteLine("多线程拷贝已启动，按任意键退出...");

        Console.ReadKey();

    }

}
